package com.wn.ticket.web.backstage;

import com.wn.ticket.common.ResponseEntity;
import com.wn.ticket.entity.Notice;
import com.wn.ticket.entity.Perform;
import com.wn.ticket.service.NoticeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.stream.Collectors;

@RestController
@RequestMapping("/backstage/notice")
public class NoticeController {

    @Autowired
    private NoticeService noticeService;

    @PreAuthorize("hasAnyAuthority('super')")
    @PostMapping("/add")
    public ResponseEntity add(@RequestBody Notice notice){
       try {
           noticeService.add(notice);
       }catch (Exception e){
           e.printStackTrace();
           return new ResponseEntity("400", "fail", e.getMessage());
       }
        return ResponseEntity.success;
    }

    @PreAuthorize("hasAnyAuthority('super')")
    @RequestMapping("/deleted/{id}")
    public ResponseEntity deleted(@PathVariable int id) {
        try {
            noticeService.del(id);
        }catch (Exception e){
            e.printStackTrace();
            return new ResponseEntity("400", "fail", e.getMessage());
        }
        return ResponseEntity.success;
    }

    @RequestMapping("/getAll")
    public ResponseEntity<Notice> getAll(){
        List<Notice> noticeList = noticeService.getAll();

        return new ResponseEntity("200","ok", noticeList);
    }
}
